package com.syaccp.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syaccp.model.Customer;
import com.syaccp.service.CustomerService;
import com.syaccp.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

/**
 * <p>
 * 客户表 前端控制器
 * </p>
 *
 * @author hsx
 * @since 2023-07-30
 */
@RestController
@RequestMapping("/t_customer")
public class TCustomerController {

    @Autowired
    private CustomerService CustomerService;

    //总营业额
    @PostMapping("/turnoverSum")
    public Result turnoverSum(){
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("sum(consume_money) as consumeMoney");
        Map<String, Object> map = CustomerService.getMap(queryWrapper);
        return Result.success(map.get("consumeMoney"));
    }

    //客户钱包余额  可提现金额
    @PostMapping("/balanceSum")
    public Result BalanceSum(){
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("sum(balance) as totalBalance");
        Map<String, Object> map = CustomerService.getMap(queryWrapper);
        return Result.success(map.get("totalBalance"));
    }



}
